home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 355 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.mindspring.com!usenet
  2. From: rudd@mindspring.com (Justin Rudd)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: help on syntax
  5. Date: 4 Jan 1996 00:44:34 GMT
  6. Organization: N/A
  7. Message-ID: <4cf7ti$14sk@firehose.mindspring.com>
  8. References: <96002.222728APCCU@CUNYVM.CUNY.EDU>
  9. NNTP-Posting-Host: rudd.mindspring.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. >      if (c = (a-b))
  15. >          cout << "a: ";
  16. >          cout << a;
  17. >          cout << " minus b: ";
  18. >          cout << b;
  19. >          cout << " quals c: ";
  20. >          cout << c << endl;
  21. >      else
  22. >          cout << "a-b does not equal c: " << endl;
  23. >}
  24.  
  25. Well first off if you are trying to check to see if C equals (a-b) you need to 
  26. use the double equals marks: ==.  What you are doing is assigning a-b to c.  
  27. Also since you have more then one statement after the if you need braces like 
  28. this:
  29.        if( c == (a-b))
  30.        {//opening brace
  31.              cout << "a: ";
  32.              //the rest of your stuff here
  33.        }//closing brace
  34.  
  35. >    if (c = (a-b))
  36. >         cout << "a: " << a << " minus b: " << b << " equals c: " << c;
  37. >    else
  38. >         cout << "a-b does not equal c: ";
  39. >}
  40.  
  41. The if statement should also be using the double equals marks: == to check for 
  42. equality.  Also the reason this if statement works is because you only have 
  43. one statement following the if.
  44.  
  45. Justin Rudd
  46. rudd@mindspring.com
  47. http://www.mindspring.com/~jleonard/
  48. (334)-855-4680
  49.  
  50.  
  51.  
  52.